<?php
class AccountAccountGeneral implements Account_WebService_Account_General_V1r0_GeneralInterface
{        
    /**
     * @var Account_Lib_Remote_Invoker_ReadService
     */
    private $_readService;
    
    /**
     * @var Account_Lib_Remote_Invoker_WriteService
     */
    private $_writeService;
    
    /**
     * @param Account_Lib_Remote_Invoker_ReadService $readService
     * @param Account_Lib_Remote_Invoker_WriteService $writeService
     */
    public function __construct(
        Account_Lib_Remote_Invoker_ReadService $readService,
        Account_Lib_Remote_Invoker_WriteService $writeService
    )
    {
        $this->_readService = $readService;
        $this->_writeService = $writeService;
    }
    
	/**
     * Return account information
     * 
     * Return:
     *  - account-inforamtion
     *  - account-owner-information
     *  - account-owner-emails
     *  - passwords
     *  
     *  - isLoged
     * 
     * @param string $emailAddress
     * 
     * @return array
     */
    public function getAccountInformation($emailAddress)
    {
        try{
            return $this->_readService->getAccountInformation($emailAddress);           
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }    
    }
     
    /**
     * Create new account
     * 
     * ownerInformation keys:
     *  - string $firstName
     *  - string $lastName
     *  - string $dateOfBirth
     *  - string $gender
     *  - string $nickName
     *  - string $mobileNumber
     *  - string $homeNumber
     *  - string $additionalInformation
     *  
     * deliveryInformation keys:
     *  - string $country
     *  - string $city
     *  - string $postCode
     *  - string $street
     *  - string $houseNumber
     *  - string $secondAddressLine
     *  - string $thirdAddressLine
     *  - string $additionalInformation 
     *  
     * settings keys:
     *  - locale keys:
     *    - array country 
     *       - string code
     *       - string title
     *    - array language 
     *       - string code
     *       - string title
     * 
     * @param string $customerEmail
     * @param string $password
     * @param string $passwordAgain
     * @param array $ownerInformation
     * @param array $deliveryInformation
     * @param array $settings
     * @param boolean $passwordAutoGenerated
     * 
     * @return void
     */
    public function setupAccount(
        $customerEmail, 
        $password, 
        $passwordAgain, 
        array $ownerInformation = array(),
        array $deliveryInformation = array(),
        array $settings = array(),
        $passwordAutoGenerated = false
    )
    {
        try{
            $this->_writeService->setupAccount(
                $customerEmail, 
                $password, 
                $passwordAgain,
                $ownerInformation,
                $deliveryInformation,
                $settings,
                $passwordAutoGenerated
            );     
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }        
    }
         
    /**
     * Activate account by confirmg primary email address
     * 
     * @param string $customerEmail
     * @param string $activationKey
     * 
     * @return void
     */
    public function activateAccount($customerEmail, $activationKey)
    {
        try{
            $this->_writeService->activateAccount($customerEmail, $activationKey);
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }          
    }
         
    /**
     * Authenticate customer
     *
     * @param string $customerEmail
     * @param string $password
     * 
     * @return void
     */
    public function login($customerEmail, $password)
    {
        try{
            $this->_writeService->login($customerEmail, $password);
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }          
    }
    
    /**
     * Logout customer
     * 
     * @param string $customerEmail
     * 
     * @return void
     */
    public function logout($customerEmail)
    {
        try{
            $this->_writeService->logout($customerEmail);
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }          
    }
    
	/**
     * Reset password
     * 
     * @param string $customerEmail
     * 
     * @return void
     */
    public function remindPassword($customerEmail)
    {
        try{
            $this->_writeService->remindPassword($customerEmail);
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }          
    }         
    
    /**
     * Remind email activation key
     * 
     * @param string $customerEmail
     * 
     * @return void
     */
    public function remindActivationKey($customerEmail)
    {
        try{
            $this->_writeService->remindActivationKey($customerEmail);
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }          
    }         
    
	/**
     * Delete account
     * 
     * @param string $customerEmail
     * 
     * @return void
     */
    public function deleteAccount($customerEmail)
    {
        try{
            $this->_writeService->deleteAccount($customerEmail);
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }          
    }         
    
	/**
     * Chnage password
     * 
     * @param string $customerEmail
     * @param string $password
     * 
     * @return void
     */
    public function changePassword($customerEmail, $password)
    {
        try{
            $this->_writeService->changePassword($customerEmail, $password);
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }          
    }         
      
       
    /**
     * Create new products in account
     * 
     * @param string $customerEmail
     * @param array $products
     * 
     * @return void
     */
    public function addNewProductsInAccount($customerEmail, array $products)
    {
        try{
            $this->_writeService->addProductsToAccount(
                $customerEmail, 
                $products
            );       
        } catch(Exception $ex) {
            throw new SoapFault('0', $ex->getMessage());
        }         
    }
}